<?php
ob_start();
session_start();
include_once("../UserIncludes/DbConfig.php");
set_magic_quotes_runtime(1);
if(strpos($_REQUEST[adspaceid],','))
{
	$adspId = substr($_REQUEST[adspaceid],0,strlen($_REQUEST[adspaceid])-1);
	$duplicateArr = mysql_fetch_array(mysql_query("select adspaceId from ".FAVADSPACE." where userId='".$_SESSION[siteuserId]."'"));
	
	$explode_adspId = explode(',',$adspId);
	$j=0;
	for($i=0;$i<count($explode_adspId);$i++)
	{
		
		$sql = "insert into ".FAVADSPACE." set userId='".$_SESSION[siteuserId]."' , adspaceId='".$explode_adspId[$i]."', addedOn='".date('Y-m-d')."'";
		if(!in_array($explode_adspId[$i],$duplicateArr))
		{	$j++;
			mysql_query($sql);
		}
	}
if($j==0)
	echo '<div style="width:750px;height:40px;border:#999999 thin solid; vertical-align:middle;" class="err_class"><br>No new adspace has been added to your favourite list</div>';
else
	echo '<div style="width:750px;height:40px;border:#999999 thin solid; vertical-align:middle;" class="err_class"><br>'.$j.' adspace(s) has been added to your favourite list</div>';
}
else
{
	$sql = "insert into ".FAVADSPACE." set userId='".$_SESSION[siteuserId]."' , adspaceId='".$_REQUEST[adspaceid]."', addedOn='".date('Y-m-d')."'";
	mysql_query($sql);
	echo '<script>window.location="../adSpaceDetails.php?fav=yes&id='.$_REQUEST[adspaceid].'"</script>';
}
?>

